//
//  FeedbackViewController.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/8/6.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "FeedbackViewController.h"

@interface FeedbackViewController ()<UITextViewDelegate>

@end

@implementation FeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"建议反馈";
    self.view.backgroundColor = REXADECIMALCOLOR(@"#eeeeee");
    [self setUI];
}

- (void)setUI {
    UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(20), SCREEN_WIDTH, ScreenX375(16))];
    noteLabel.text = @"请填写您的建议和反馈";
    noteLabel.font = Kfont(16);
    noteLabel.textColor = REXADECIMALCOLOR(@"#888888");
    [self.view addSubview:noteLabel];
    
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(48), SCREEN_WIDTH - ScreenX375(32), ScreenX375(186))];
    textView.layer.cornerRadius = ScreenX375(6);
    textView.font = Kfont(16);
    textView.textColor = REXADECIMALCOLOR(@"#212121");
    textView.backgroundColor = [UIColor whiteColor];
    textView.delegate = self;
    textView.tag = 666;
    [self.view addSubview:textView];
    
    UIButton *saveBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - ScreenX375(49), SCREEN_WIDTH, ScreenX375(49))];
    [saveBtn setTitle:@"提交" forState:UIControlStateNormal];
    [saveBtn setBackgroundImage:[UIImage imageNamed:@"按钮背景"] forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = Kfont(18);
    [saveBtn addTarget:self action:@selector(commit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:saveBtn];
}

- (void)commit {
    UITextView *textView = [self.view viewWithTag:666];
    if (textView.text.length == 0) {
        [HttpManager showNoteMsg:@"请输入反馈内容"];
        return;
    }
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@api/feedback",REQUESTHEADER] andParameter:@{@"userId":kNSUDefaultReadKey(@"userId"),@"content":textView.text} success:^(id successResponse) {
        NSString *code = [NSString stringWithFormat:@"%@",successResponse[@"code"]];
        if ([code isEqualToString:@"200"]) {
            [HttpManager showNoteMsg:@"反馈成功"];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"message"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showNoteMsg:@"反馈失败,请稍后再试"];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
